<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <!-- https://www.bilibili.com/video/BV14k4y117LL?p=5 -->
    <div id="app">
      <form action="#" onsubmit="return false">
        <input type="text" v-model="user.name" />name
        <input type="text" v-model="user.id" />id
        <button @click="add" type="submit">add</button>
      </form>
      <ul>
        <li v-for="(item,index) in list" :key="item.id" @click="del(index)">
          {{ item.name }}-{{item.id}}
        </li>
      </ul>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.0.0/vue.global.js"></script>
    <script>
      let appConfig = {
        data() {
          return {
            list: [
              {
                name: "wxs",
                id: 0,
              },
              {
                name: "wxs1",
                id: 1,
              },
              {
                name: "wxs2",
                id: 2,
              },
            ],
            user: {
              name: "",
              id: "",
            },
          };
        },
        methods: {
          del(index) {
            this.list = this.list.filter((item, i) => i !== index);
          },
          add(e) {
            e.preventDefault();
            // let user2 = this.user;
            // this.list.push(user2);
            // user2 = {};
            let tempUser = Object.assign({}, this.user);
            this.list.push(tempUser);
            this.user = {};
          },
        },
      };
      Vue.createApp(appConfig).mount("#app");
    </script>
  </body>
</html>
